package com.jinlia.show.modules.system;

import net.coobird.thumbnailator.Thumbnails;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Img {
    public static void splitImage(String inputImagePath, String outputDirectory, int maxHeight) throws IOException {
        BufferedImage originalImage = ImageIO.read(new File(inputImagePath));
        int height = originalImage.getHeight();
        int parts = (int) Math.ceil((double) height / maxHeight);

        File outputDir = new File(outputDirectory);
        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }

        for (int i = 0; i < parts; i++) {
            int startY = i * maxHeight;
            int partHeight = Math.min(maxHeight, height - startY);

            Thumbnails.of(originalImage)
                    .sourceRegion(0, startY, originalImage.getWidth(), partHeight)
                    .scale(1.0)
                    .toFile(new File(outputDir, "part_" + (i + 1) + ".png"));
        }
    }

    public static void main(String[] args) {
        String reg = "S{2}\\d+";
        System.out.println("S2024565".matches(reg));
    }
}
